package com.cnr.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.cnr.util.ManageCredentials;

@Controller
@RequestMapping("/create")
public class CreatorController {

        @RequestMapping(value = "/user", method = RequestMethod.POST)
        public String addUser(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        @RequestParam("passwordRepeat") String passwordRepeat,
                        @RequestParam("email") String email,
                        @RequestParam("role") String role, HttpSession session, Model model) {

                ManageCredentials mc = new ManageCredentials();
                if (password.equals(passwordRepeat)) {
                        mc.addCredentials(username, password, email, role);
                        return "identified";
                }

                model.addAttribute("message", "Entered passwords do not match!");
                return "error";

        }

}